﻿using Newtonsoft.Json;

namespace IcbcOpenDemo.Models
{
    // 所有API类父类，定义了将API子类输出成JSON字符串方法
    public abstract class BaseAPI
    {
        #region 生成JSON的一些设置
        // 生成是JSON串是否使用缩进格式，测试开发时选Formatting.Indented，生产环境上可设置Formatting.None以节省带宽
        //private Formatting format = Formatting.Indented;
        private Formatting format = Formatting.None;

        private JsonSerializerSettings settings = new JsonSerializerSettings
        {
            NullValueHandling = NullValueHandling.Include
        };
        #endregion

        public abstract string GetPath();

        public string ToJsonString()
        {
            //return "{" + JsonConvert.SerializeObject(this, format, settings) + "}";
            return JsonConvert.SerializeObject(this, format, settings);
        }
    }
}
